package com.fsq.util;

import com.alibaba.fastjson.JSONObject;
import com.fsq.token.UserToken;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class WebContextUtil {

    private static Map<String, String> tokenCache = new ConcurrentHashMap<>();

    /**
     * 设置token信息
     *
     * @param content
     */
    public static void setUserToken(String phone, String content) {
        tokenCache.put(phone, content);
    }

    /**
     * 获取token信息
     *
     * @return
     */
    public static UserToken getUserToken(String phone) {
        if (tokenCache.containsKey(phone)) {
            UserToken userToken = JSONObject.parseObject(tokenCache.get(phone), UserToken.class);
            return userToken;
        }
        return null;
    }


    /**
     * 移除token信息
     *
     * @return
     */
    public static void removeUserToken(String phone) {
        if (tokenCache.containsKey(phone)) {
            tokenCache.remove(phone);
        }
    }
}
